//
//  LoginViewController.m
//  ElectronicSandTable
//
//  Created by 苏晓凯 on 2017/6/16.
//  Copyright © 2017年 苏晓凯. All rights reserved.
//

#import "LoginViewController.h"
#import "JGProgressHUD.h"
#import "DetailViewController.h"
#import "IQKeyboardManager.h"
#import "AppDelegate.h"
@interface LoginViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *txtAccount;
@property (weak, nonatomic) IBOutlet UITextField *txtPassword;
@property (weak, nonatomic) IBOutlet UIButton *btnLogin;
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UIView *view2;

@property (nonatomic, retain) NSMutableDictionary       *accountDic;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES];
    self.btnLogin.layer.masksToBounds = YES;
    self.btnLogin.layer.cornerRadius = 5.f;
    
    self.view1.layer.masksToBounds = YES;
    self.view1.layer.cornerRadius = 5.f;
    
    self.view2.layer.masksToBounds = YES;
    self.view2.layer.cornerRadius = 5.f;
    
    self.accountDic = [[NSMutableDictionary alloc] init];
    [self.accountDic setObject:@"HC135246" forKey:@"huachuan1"];
    [self.accountDic setObject:@"HC135246" forKey:@"huachuan2"];
    [self.accountDic setObject:@"HC135246" forKey:@"huachuan3"];
    [self.accountDic setObject:@"HC135246" forKey:@"huachuan4"];
    [self.accountDic setObject:@"HC135246" forKey:@"huachuan5"];
    NSString *yesstr = [[NSUserDefaults standardUserDefaults] objectForKey:@"login"];
    if (yesstr) {
        DetailViewController *detailVc = [[DetailViewController alloc]init];
        [self.navigationController pushViewController:detailVc animated:YES];
        self.txtAccount.text = yesstr;
        self.txtPassword.text = @"HC135246";
    }

    // Do any additional setup after loading the view from its nib.
}
-(void)showJGProgressWithMsg:(NSString *)msg{
    JGProgressHUD *HUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
    HUD.indicatorView = nil;
    HUD.textLabel.text = msg;
    HUD.position = JGProgressHUDPositionBottomCenter;
    HUD.marginInsets = (UIEdgeInsets) {
        .top = 0.0f,
        .bottom = 20.0f,
        .left = 0.0f,
        .right = 0.0f,
    };
    [HUD showInView:[[[UIApplication sharedApplication] windows] firstObject]];
    
    [HUD dismissAfterDelay:2.0];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)loginAction:(id)sender {
    if (![self.accountDic.allKeys containsObject: self.txtAccount.text ]) {
        [self showJGProgressWithMsg:@"请输入正确的账号"];
        return;
    }
    if (![self.txtPassword.text isEqualToString:@"HC135246"]) {
        [self showJGProgressWithMsg:@"请输入正确的密码"];
        return;
        
    }
    [[NSUserDefaults standardUserDefaults] setObject:self.txtAccount.text forKey:@"login"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    DetailViewController *detailVc = [[DetailViewController alloc]init];
    [self.navigationController pushViewController:detailVc animated:YES];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

//
//
//-(void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//    AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    delegate.allowRotate = 0;
//}
//-(void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
//    
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
